package org.thirdHero.db.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq配置类
 * 员工系统配置延时队列
 * @author zhanghang
 * @date 2019/1/7
 */
@Configuration
public class RabbitUserConfig {

    /**
     * 延时队列交换机
     * 注意这里的交换机类型：CustomExchange 
     * @return
     */
    @Bean
    public TopicExchange payOverTimeExchange(){
        return new TopicExchange("payOverTimeExchange");
    }
    @Bean
    public TopicExchange receiverOverTimeExchange(){
        return new TopicExchange("receiverOverTimeExchange");
    }
    /**
     * 延时队列
     * @return
     */
    @Bean
    public Queue overTimeQueue(){
        return new Queue("overTimeQueue",true);
    }


    @Bean
    public Queue receiverOverTimeQueue(){
        return new Queue("receiverOverTimeQueue",true);
    }
    /**
     * 给延时队列绑定交换机
     * @return
     */
    @Bean
    public Binding overTimeQueueBinding(Queue overTimeQueue, TopicExchange payOverTimeExchange){
        return BindingBuilder.bind(overTimeQueue).to(payOverTimeExchange).with("overTime.#");
    }

    @Bean
    public Binding receiverOverTimeBinding(Queue receiverOverTimeQueue,TopicExchange receiverOverTimeExchange){
        return BindingBuilder.bind(receiverOverTimeQueue).to(receiverOverTimeExchange).with("receiverOverTime.#");
    }
}